-
Notifications
You must be signed in to change notification settings - Fork 89
add screenshots to components gallery #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add screenshots to components gallery #125
Conversation
Build process cleaned up and updated, looks like that now: const componentsBuildIndex = require('./src/components-build-index');
const componentsBuildPages = require('./src/components-build-pages');
const componentsBuildScreenshots = require('./src/components-build-screenshots');
const globPattern = 'src/components/cards/*.html';
componentsBuildIndex(globPattern)
.then(componentsForNavPath => componentsBuildPages(componentsForNavPath))
.then(componentsForNavPath => componentsBuildScreenshots(componentsForNavPath))
.then(() => {
console.log('All done');
})
.catch((err) => {
console.log(err);
}); You may need Node 6 as I used ES2015 "modern" syntax :) The first step, which builds the index, now create an intermediate file {
"cards": [
{
"name": "Album Centered",
"title": "Cards Album Centered",
"src": "src/components/cards/album-centered.html",
"path": "components/cards/album-centered/index.html",
"href": "/components/cards/album-centered/index.html",
"screenshot": {
"path": "components/cards/album-centered/screenshot.png",
"href": "/components/cards/album-centered/screenshot.png"
},
"frontMatter": {
"bodyClass": "bg-white pt5"
}
}, |
Add component signature, a hash of the Tachyons version and component contents, so it can be used to bust the browser cache for screenshots. If the server delivering these pages is setup correctly, a user returning to the components page should not re-download the screenshots, but use the ones in the cache instead, UNLESS the signature has changed, in which case they will be re-downloaded. Win-win. @mrmrs @johnotander I assume you are using Github Pages? We will have to test, it's unclear how caching is setup, though it might be something a bit too short like 10 minutes :( See javascript - Determining a page is outdated on github pages, How to solve caching problem with Github Pages, Caching assets in Github pages (github.io) {
"banners": [
{
"name": "Basic",
"title": "Banners Basic",
"src": "src/components/banners/basic.html",
"path": "components/banners/basic/index.html",
"href": "/components/banners/basic/index.html",
"screenshot": {
"path": "components/banners/basic/screenshot.png",
"href": "/components/banners/basic/screenshot.png?version=71b1b1c5aac3d21f986dd404d9f0f70f"
},
"signature": "71b1b1c5aac3d21f986dd404d9f0f70f",
"frontMatter": {
"bodyClass": "bg-white pt5"
}
}, |
Phew.
There you go, 21MB to 3.6MB already, and the optimizer is not even there. There is no algorithm that can perfectly fit the screenshot in the gallery layout, but this can be tweaked per component. I reviewed 150 of them (again), and nudged them accordingly. In the frontmatter, one can play with any one of these to change the defaults:
|
Alright folks,
I believe this should do the trick until you decide the gallery needs to be fragmented (I'm partial to a single page), but I got to work on other projects :) Hit me up though. The compression quality and screenshot size can be tweaked in the future (check @mrmrs @johnotander what do you think? You guys will be the ones adding components, I cleaned up I haven't committed the new, generated gallery, just the source files. Give it a shot. It slower though, unsurprisingly, it took about 5 mins to re-create it on a 2016 MBP. With that being said it should be easy to create a "Featured" gallery, or an index to category pages, with only one "featured" screenshot per category in that index. I would slap: |
Hey @sebastienbarre, thank you so much for your contribution. This is amazing! Just ran the build and did some testing locally. Works perfectly. The lazy loading of the images keeps the main component page pretty lightweight which is way rad. Everything looks good to me 👍 but I'll wait for @mrmrs to have a look to see if he has any thoughts or wants to tweak things. I appreciate the time you took adding feedback to the build process, too. That's an aspect we've been needing to improve for a very long time : ). |
@sebastienbarre you are my hero. This is all really rad. Great example of how to put together a solid PR. Appreciate all of your hard work here. Excited to launch this. |
Thanks folks, glad I could help. |
Howdy.
Love the components gallery in Tachyons, but the list is growing so fast I'm starting to get lost :)
This PR adds a new build script that creates screenshots for each component.
src/components-build.s
was updated to return a promise (since it is asynchronous), so that another script can be executed after it has fully completed.src/components-screenshots-build.js
takes care of creating the screenshots and return a promise as well (since it is asynchronous).build.js
was updated to handle the promises returned by the above.Screenshots are created automatically. A bare-bone Express static HTML server is started and used to load each component page one by one for capture. The component template was updated to wrap each component inside a
<div data-name="component-container">
so that the corresponding area in the page can be captured.This works for the vast majority of them. Some components needed a bit of help, and for that the front matter was leveraged to instruct the script on how best to extract and format the screenshot. For example, most of the buttons examples needed this small change:
<div data-name="screenshot">
has been placed around a specific subset of buttons -- without it, the page is so large that one can barely see the difference between each buttons.background-position
attribute is used above to override the defaultcenter center
in the template.Another option:
to have Tachyons use
contain
instead ofcover
for the screenshot.This PR only contains the scripts and updates to some of the components and templates. I can push the generated pages as well (i.e. the whole
components
dir and screenshots).TODO:
Here is the whole page: